package com.jweb.core.handle;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.jweb.core.JWebFilter;
import com.jweb.util.FormatUtil;
/**
 * 请求信息
 * @author Yuan
 */
public class Action {

	private final Class<? extends Controller> controllerClass;
	private final String controllerKey;
	private final Method method;
	private final String methodName;
	private final String viewPath;
	private final String paramStr;
	private final List<String> paramList;
	private final String CR = "/";
	private final String ViewPrefix = JWebFilter.getConstants().get("ViewPrefix");
	private final String ViewSuffix = JWebFilter.getConstants().get("ViewSuffix");

	public Action(String controllerKey, Class<? extends Controller> controllerClass, Method method, String methodName, String paramStr) {
		this.controllerKey = controllerKey;
		this.controllerClass = controllerClass;
		this.method = method;
		this.methodName = methodName;
		this.paramStr = paramStr;
		this.paramList = !FormatUtil.isEmpty(paramStr)? Arrays.asList(paramStr.split(CR)) : new ArrayList<String>();
		this.viewPath = ViewPrefix + controllerKey.toLowerCase() + CR + method.getName() + ViewSuffix;
	}

	public String getParamStr() {
		return paramStr;
	}

	public List<String> getParamList() {
		return paramList;
	}

	public Class<? extends Controller> getControllerClass() {
		return controllerClass;
	}

	public String getControllerKey() {
		return controllerKey;
	}

	public Method getMethod() {
		return method;
	}

	public String getViewPath() {
		return viewPath;
	}

	public String getMethodName() {
		return methodName;
	}
}
